import QtQuick 2.0
import QtQuick.Controls

Window {
    height: 600
    width: 800
    title: "文件比较"
    //需要更新的列表
    property var lst: []

    ButtonGroup {
        id: ckgp
        exclusive: false
        checkState: pBox.checkState
    }

    CheckBox {
        id: pBox
        text: qsTr("全选")
        anchors.left: parent.left
        anchors.leftMargin: 5
        checkState: ckgp.checkState
    }

    ListView { //不同的显示列表
        id: chfile
        anchors.top: parent.top
        anchors.topMargin: 25
        height: 500
        width: 800
        model: lst
        delegate: Item {
            width: 800
            height: 20
            CheckBox {
                width: 20
                height: 20
                anchors.left: parent.left
                anchors.leftMargin: 5
                ButtonGroup.group: ckgp
            }
            //本地文件
            Image {
                width: 20
                height: 20
                anchors.left: parent.left
                anchors.leftMargin: 20
                source: modelData.fileName?("resource/" + (modelData.isDir?"box.png":"file.png")):"resource/file.png"
            }
            Text {
                width: 300
                anchors.left: parent.left
                anchors.leftMargin: 50
                text: modelData.fileName?("[" + modelData.Size + "]" + modelData.fileName):""
            }
            Text {
                width: 30
                lineHeight: 20
                anchors.left: parent.left
                anchors.leftMargin: 350
                text: "<=>"
            }
            //盘文件
            Image {
                width: 20
                height: 20
                anchors.left: parent.left
                anchors.leftMargin: 385
                source: modelData.server_filename?("resource/" + (modelData.isdir?"box.png":"file.png")):""
            }
            Text {
                width: 300
                anchors.left: parent.left
                anchors.leftMargin: 410
                text: modelData.server_filename?("[" + modelData.size + "]" + modelData.server_filename):""
            }
        }
    }

    Button {
        anchors.top: parent.top
        anchors.topMargin: 550
        anchors.left: parent.left
        anchors.leftMargin: parent.width / 2 - 20
        text: "下载"
        onClicked: {
            let sfl = [];
            for(let i=0;i<ckgp.buttons.length;i++){
                if(ckgp.buttons[i].checked){
                    sfl.push(lst[i]);
                }
            }
            if(sfl.length){
                transfer.pushfiles(sfl);
                cmpui.visible = false;
            }else{
                htooltip.show("请选择下载的文件");
            }
        }
    }

    /** 变化文件列表 */
    function updateFile(fls){
        lst = fls;
        //console.log(JSON.stringify(lst));
        chfile.model = lst;
    }
}
